/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-09-17
 * Time: 22:24
 */
public class Test95 {

    public static void main(String[] args) {
        String s = "babad";

    }

    public String longestPalindrome(String s) {
        int n = s.length();
        boolean[][] dp = new boolean[n][n];
        int begin = 0, len = 0;
        for(int i = n-1; i >= 0; i--) {
            for(int j = i; j < n; j++) {
                if(s.charAt(i) == s.charAt(j)) {
                    dp[i][j] = i+1 < j ? dp[i+1][j-1] : true;
                }
                if(dp[i][j] && j-i+1 > len) {
                    begin = i;
                    len = j-i+1;
                }
            }
        }
        return s.substring(begin,begin+len);
    }
}
